
var UserGrid = function(){
   
    var grid;
    var search_tip = 'type here to search';
    
    function init(params) {
        
        grid = $("#user_grid");
        
        var options = {
            url: 'users/getItems',
            datatype: 'json',
            mtype: "GET",
            height: 260,
            width: 950,
            colNames:['Email', 'Full Name','Role','State','Created'],
            colModel :[{
                name:'username', 
                index:'username',	
                width:40,
                search:true,
                stype:'text',
                align:'left',
                classes: '',
                searchoptions:{
                    defaultValue: search_tip
                }
            },
            {
                name:'full_name', 
                index:'fule_name',	
                width:40,
                search:true,
                stype:'text',
                align:'left',
                classes: '',
                searchoptions:{
                    defaultValue: search_tip
                }
            },
            {
                name:'role', 
                index:'role',	
                width:40,
                search:true,
                stype:'text',
                align:'left',
                classes: '',
                searchoptions:{
                    defaultValue: search_tip
                }
            },
            {
                name:'active', 
                index:'active',	
                width:40,
                search:true,
                stype:'select',
                align:'left',
                classes: '',
                searchoptions: {
                    value:":All;0:Inactive;1:Active;"
                }
            },
            {
                name:'created', 
                index:'created', 
                width:25,
                search:true,
                stype:'text',
                align: 'left',
                searchoptions: {
                    defaultValue: search_tip
                }
            }],
            multiselect: true,
            viewrecords: true,
            caption: '',
            scrollOffset: 1,
            loadonce: false,
            rownumbers: false,
            rownumWidth: 30,
            gridview: true,
            pager: '#user_grid_pager',
            sortname: 'created',
            sortorder: 'desc',
            rowNum: 10,
            rowList: [10, 15, 20, 100],
            recordpos: 'right',
            altRows: true
        }
        
        grid.jqGrid(options); 			
        
        grid.jqGrid('filterToolbar', {
            stringResult: true, 
            autosearch: true,
            searchOnEnter : false
        });
		
        grid.jqGrid('navGrid','#user_grid_pager',{del:false,add:false,edit:false,search:false,refresh:true});
        
        grid.jqGrid('bindKeys', {} );
    }
    
    return {
        init: init
    }
}();

$(document).ready(function(){
	
//    $("#user_grid").jqGrid({
//            url: '/users/getItems',
//            width: 700,
//            height: 200,
//            mtype: 'GET',
//            datatype: 'json',
//            colNames:['Full Name', 'E-mail', 'Privilegii','Status','Creat'],
//            colModel:[
//                    {name:'full_name',index:'full_name', width:55, align:'left'},
//                    {name:'user_name',index:'user_name', width:90, align:'left'},
//                    {name:'rank',index:'rank', width:100, align:'left'},
//                    {name:'active',index:'active', width:100, align:'left'},
//                    {name:'created', index:'created', width:80, align:'left'}],
//
//            rowNum:10,
//            rowList:[10,20,30,50],
//            pager: $('#user_grid_pager'),
//            sortname: 'created',
//            viewrecords: true,
//            sortorder: "desc",
//            gridview: true
//    });

    UserGrid.init();
});